<%--
  Created by IntelliJ IDEA.
  User: 1daon
  Date: 2019/1/18
  Time: 9:43 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html class="dialog-page">
<head>
    <jsp:include page="../common/backend_head.jsp"/>
    <link rel="stylesheet" href="/plugin/jquery.ztree/css/zTreeStyle/zTreeStyle.css" />
    <style type="text/css">
        #img-avatar {
            width: 30px;
            height: 30px;
            margin-top: 3px;
        }
        .ztree li span.button.chk.checkbox_false_part{background-position: 0 0}
        .ztree li span.button.chk.checkbox_true_part {background-position: -14px 0}
    </style>
</head>
<body>
<div class="layui-fluid">
    <form action="/sys/sysUser/add.do" method="post" id="validate-form" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="lable-condition-must" data-msg="学生可以不填"></span>手机号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" placeholder="请输入手机号（本系统登录账号）" id="user_mobile" name="userMobile" isMobile="true" maxlength="11" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="请输入真实姓名" id="user_true_name" name="userTrueName" required maxlength="20" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
                <input type="text" name="deptId" id="dept_id" class="layui-input" readonly="readonly" autocomplete="off" required />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <input type="text" name="roleId" id="role_id" class="layui-input" readonly="readonly" autocomplete="off" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职务</label>
            <div class="layui-input-block">
                <input type="text" name="postId" id="post_id" class="layui-input" readonly="readonly" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" placeholder="请输入密码" id="user_password" name="userPassword" required minlength="6" maxlength="16" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="userSex" value="1" title="男" checked>
                <input type="radio" name="userSex" value="2" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" placeholder="请输入昵称" id="user_nickname" name="userNickname" maxlength="10">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="lable-condition-must" data-msg="使用工资查询模块时必须输入"></span>身份证号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" placeholder="请输入身份证号（工资查询时必填项目）" id="user_id_card" name="userIdCard" isIdCardNo="true" maxlength="18">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">生日</label>
            <div class="layui-input-inline" style="width: 95px;">
                <input type="text" class="layui-input" placeholder="请输入生日" id="user_birthday" name="userBirthday" maxlength="15">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-sm" id="upload_file">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
                <img id="img-avatar" src="/images/common/avatar.png" alt="头像">
                <input type="hidden" name="userAvatar" id="user_avatar" value="/images/common/avatar.png">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="lable-condition-must" data-msg="选填"></span>邮箱</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" placeholder="请输入邮箱（可用来找回密码）" id="user_email" name="userEmail" email="true" maxlength="50">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="userStatus" value="1" title="启用" checked />
                <input type="radio" name="userStatus" value="2" title="禁用"  />
            </div>
        </div>
        <div class="layui-button-footer">
            <a href="javascript:void(0);" onclick="checkMobile();" class="layui-btn layui-btn-warm"><i class="iconfont icon-save"></i>检测手机号是否存在</a>
            <a href="javascript:void(0);" class="layui-btn submit-btn"><i class="iconfont icon-save"></i>保存</a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-primary close-btn"><i class="iconfont icon-round_close_light"></i>关闭</a>
        </div>
    </form>
</div>
</body>
<jsp:include page="../common/backend_script.jsp"/>
<script src="/plugin/jquery.ztree/js/jquery.ztree.all.min.js"></script>
<script src="/js/backend/tree.js"></script>
<script type="text/javascript">
    layui.laydate.render({
        elem: '#user_birthday',
        type: 'date'
    });
    var layer_index;
    layui.upload.render({
        elem: '#upload_file',
        url: '/sys/sysUser/upload.do',
        accept: 'file',
        before: function(obj) {
            layer_index = layer.msg('文件上传中······', {
                icon: 16,
                time: 0
            });
        },
        done: function(res) {
            if(res.status == 0){
                $('#img-avatar').attr('src', res.data.thumbnailPath);
                $('#user_avatar').val(res.data.path);
                layer.close(layer_index);
            } else {
                layer.close(layer_index);
                layer.msg(res.msg, { icon: 5 });
            }
        },
        error: function() {
            layer.close(layer_index);
            layer.msg('上传错误！', { icon: 5 });
        }
    });

    $(document).ready(function() {
        // 组织机构
        $("#dept_id").SelectTree({
            'nodes': ${sysDeptList},
            'defaultValue': '${deptId}',
            'idKey': 'deptId',
            'pIdKey': 'deptPid',
            'name': 'deptName',
            'height': 300,
            'check' : {
                'enable': true,
                'chkboxType' : { "Y" : "", "N" : "" }
            }
        });
        // 角色
        $("#role_id").SelectTree({
            'nodes': ${sysRoleList},
            'defaultValue': '-1',
            'idKey': 'roleId',
            'pIdKey': 'rolePid',
            'name': 'roleName',
            'height': 300,
            'check' : {
                'enable': true,
                'chkboxType' : { "Y" : "", "N" : "" }
            }
        });
        // 职务
        $("#post_id").SelectTree({
            'nodes': ${sysPostList},
            'defaultValue': '-1',
            'idKey': 'postId',
            'pIdKey': 'postPid',
            'name': 'postName',
            'height': 300,
            'check' : {
                'enable': true,
                'chkboxType' : { "Y" : "", "N" : "" }
            }
        });
    });

    function checkMobile() {
        show_loading();
        var user_mobile = $('#user_mobile').val();
        if(user_mobile != '') {
            $.ajax({
                url: '/sys/sysUser/checkMobile.do',
                type: 'POST',
                dataType: 'json',
                data: {userMobile: user_mobile},
            })
                .done(function(data, textStatus, jqXHR) {
                    if (data.status == 0) {
                        layer.msg(data.msg, {
                            icon: 5,
                            shift: 6
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 5,
                            shift: 6
                        });
                    }
                })
                .fail(function(jqXHR, textStatus, errorThrown) {
                    layer.msg('操作失败，错误代码：' + textStatus);
                })
                .always(function() {
                    close_loading();
                });
        }else{
            close_loading();
            layer.msg("请填写手机号", {
                icon: 5,
                shift: 6
            });
        }

        return false;
    }

</script>
</html>
